package com.runmyai.aitools.model;

import com.runmyai.aitools.utils.SensitiveWordsFilter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author wry
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ContentInfo {

    private String content;

    public void clean() {
        if (this.content != null) {
            String noHtml = this.content.replaceAll("<.*?>", "")
                    .trim()
                    .replaceAll("\\n{2,}", "\\n");

            // 去除敏感信息
            String noSensitive = SensitiveWordsFilter.filter(cleanEffectiveData(noHtml));
            // 去除双换行符，保留单个换行符
            this.content = noSensitive;
        }
    }

    /**
     * 清除可能影响返回结果的文本
     *
     * @param text
     * @return
     */
    private String cleanEffectiveData(String text) {
        return text;
    }

    public int getContentLength() {
        return this.content == null ? 0 : content.length();
    }
}
